import {
    /*人员*/
    EmergencyQueryPerson,
    EmergencyAddPerson,
    EmergencyEditPerson,
    EmergencyDeletePerson,
    EmergencyQueryPersonByID,
    EmergencyCommitStatus,
    EmergencyQueryPersonDetail,
    EmergencyAddPersonDetail,
    EmergencyDeletePersonDetail,
    EmergencyEditPersonDetail,
    /*装备*/
    EmergencyQueryEquip,
    EmergencyAddEquip,
    EmergencyEditEquip,
    EmergencyDeleteEquip,
    EmergencyQueryEquipCarByID,
    EmergencyQueryEquipOtherByID,
    EmergencyCommitEquipStatus,
    EmergencyQueryEquipCar,
    EmergencyQueryEquipOther,
    EmergencyAdEquipCar,
    EmergencyAddEquipOther,
    EmergencyEditEquipCar,
    EmergencyEditEquipOther,
    EmergencyDeleteEquipCar,
    EmergencyDeleteEquipOther,
    EmergencyQueryEquipByID
} from '@/services/municipal';

export default {

    namespace: 'emergency',
    state: {
        PersonList: null,
        Person: null,
        Equip:null,
        PersonDetail: null,
        EquipList:null,
        EquipCarList:null,
        EquipOtherList:null
    },
    effects: {
        /*人员*/
    
        *fetchQueryPersonList({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryPerson, payload);
            if (response.data) {
                yield put({
                    type: 'QueryPersonList',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyQueryPersonDetail({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryPersonDetail, payload);
            if (response.data) {
                yield put({
                    type: 'PersonDetail',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyQueryPersonByID({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryPersonByID, payload);
            if (response.data) {
                yield put({
                    type: 'QueryPerson',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyAddPerson({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyAddPerson, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyEditPerson({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyEditPerson, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyDeletePerson({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyDeletePerson, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyCommitStatus({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyCommitStatus, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyAddPersonDetail({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyAddPersonDetail, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyDeletePersonDetail({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyDeletePersonDetail, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyEditPersonDetail({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyEditPersonDetail, payload);
            if (callback) callback(response);
        },
        /*装备*/
        *fetchQueryEquipList({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryEquip, payload);
            if (response.data) {
                yield put({
                    type: 'QueryEquipList',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyQueryEquipByID({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryEquipByID, payload);
            if (response.data) {
                yield put({
                    type: 'Equip',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        
        *fetchEmergencyQueryEquipCar({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryEquipCar, payload);
            if (response.data) {
                yield put({
                    type: 'EquipCar',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyQueryEquipOther({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyQueryEquipOther, payload);
            if (response.data) {
                yield put({
                    type: 'EquipOther',
                    payload: response.data,
                });

            } else {
                if (callback) callback(response);
            }
        },
        *fetchEmergencyAddEquip({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyAddEquip, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyEditEquip({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyEditEquip, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyDeleteEquip({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyDeleteEquip, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyCommitEquipStatus({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyCommitEquipStatus, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyAdEquipCar({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyAdEquipCar, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyAddEquipOther({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyAddEquipOther, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyDeleteEquipCar({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyDeleteEquipCar, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyDeleteEquipOther({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyDeleteEquipOther, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyEditEquipCar({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyEditEquipCar, payload);
            if (callback) callback(response);
        },
        *fetchEmergencyEditEquipOther({ payload, callback }, { call, put }) {
            const response = yield call(EmergencyEditEquipOther, payload);
            if (callback) callback(response);
        },
    },
    reducers: {
        QueryPersonList(state, action) {

            return {
                ...state,
                PersonList: action.payload,
            };

        },
        QueryEquipList(state, action){
            return {
                ...state,
                EquipList: action.payload,
            };
        },
        Equip(state, action){
            return {
                ...state,
                Equip: action.payload,
            };
        },
        EquipCar(state, action){
            return {
                ...state,
                EquipCarList: action.payload,
            };
        },
        EquipOther(state, action){
            return {
                ...state,
                EquipOtherList: action.payload,
            };
        },
        QueryPerson(state, action) {

            return {
                ...state,
                Person: action.payload,
            };

        },
        PersonDetail(state, action) {

            return {
                ...state,
                PersonDetail: action.payload,
            };

        },
    }
}